// com.huaxin.device.controller.CircuitBreakerScheduleController
package com.huaxin.device.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huaxin.device.dto.ResponseResult;
import com.huaxin.device.dto.request.CircuitBreakerScheduleCreateReqDTO;
import com.huaxin.device.dto.request.CircuitBreakerSchedulePageListReqDTO;
import com.huaxin.device.dto.request.CircuitBreakerScheduleUpdateReqDTO;
import com.huaxin.device.models.CircuitBreakerSchedule;
import com.huaxin.device.service.CircuitBreakerScheduleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "断路器定时任务")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/device/circuitBreakerSchedule")
public class CircuitBreakerScheduleController {

    private final CircuitBreakerScheduleService service;

    @Operation(summary = "创建断路器定时任务", description = "创建一个新的断路器定时任务")
    @PostMapping("/create")
    public ResponseResult<CircuitBreakerSchedule> create(@RequestBody @Valid CircuitBreakerScheduleCreateReqDTO in) {
        return service.create(in);
    }

    @Operation(summary = "获取断路器定时任务", description = "根据ID获取任务详情")
    @GetMapping("/get")
    public ResponseResult<CircuitBreakerSchedule> get(
            @Parameter(description = "任务ID", example = "cb_sched_001")
            @RequestParam(value = "id", required = true) String id) {
        return ResponseResult.ok(service.getById(id));
    }

    @Operation(summary = "更新断路器定时任务", description = "更新断路器定时任务信息")
    @PostMapping("/update")
    public ResponseResult<String> update(@RequestBody @Valid CircuitBreakerScheduleUpdateReqDTO in) {
        return service.update(in);
    }

    @Operation(summary = "删除断路器定时任务", description = "删除指定ID的定时任务（仅允许禁用状态删除）")
    @DeleteMapping("/{id}/delete")
    public ResponseResult<String> delete(@PathVariable String id) {
        return service.delete(id);
    }

    @Operation(summary = "启用断路器定时任务", description = "启用指定任务")
    @GetMapping("/enable")
    public ResponseResult<String> enable(
            @Parameter(description = "任务ID", example = "cb_sched_001")
            @RequestParam(value = "id", required = true) String id) {
        return service.enable(id);
    }

    @Operation(summary = "禁用断路器定时任务", description = "禁用指定任务")
    @GetMapping("/disable")
    public ResponseResult<String> disable(
            @Parameter(description = "任务ID", example = "cb_sched_001")
            @RequestParam(value = "id", required = true) String id) {
        return service.disable(id);
    }

    @Operation(summary = "分页查询断路器定时任务", description = "支持按设备、名称、启用状态等条件分页查询")
    @PostMapping("/page")
    public ResponseResult<IPage<CircuitBreakerSchedule>> pageQuery(@RequestBody @Valid CircuitBreakerSchedulePageListReqDTO in) {
        return service.pageQuery(in);
    }
}